import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useTokenStore = defineStore('token', () => {
    const token = ref(localStorage.getItem('token') || '')
    const refreshToken = ref(localStorage.getItem('refreshToken') || '')

    function setToken(newToken) {
        token.value = newToken
        localStorage.setItem('token', newToken)
    }

    function setRefreshToken(newToken) {
        refreshToken.value = newToken
        localStorage.setItem('refreshToken', newToken)
    }

    function removeToken() {
        token.value = ''
        refreshToken.value = ''
        localStorage.removeItem('token')
        localStorage.removeItem('refreshToken')
    }

    return { token, refreshToken, setToken, setRefreshToken, removeToken }
})